<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <el-card shadow="hover">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="145">
            <div :style="{ 'height': `${isexpand ? 'auto' : '100px'}`, 'overflow': 'hidden' }">
              <el-form-item label="保单号" prop="policyId">
                <el-input v-model="queryParams.policyId" placeholder="请输入保单号" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="投保单号" prop="applicationId">
                <el-input v-model="queryParams.applicationId" placeholder="请输入投保单号" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="保单创建时间" prop="effectiveTime">
                <el-input v-model="queryParams.effectiveTime" placeholder="请输入保单生效时间" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="保单生效时间" prop="effectiveTime">
                <el-input v-model="queryParams.effectiveTime" placeholder="请输入保单生效时间" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="保单终止时间" prop="expireTime">
                <el-input v-model="queryParams.expireTime" placeholder="请输入保单终止时间" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="保单状态" prop="policyStatus">
                <el-input v-model="queryParams.policyStatus" placeholder="保单状态" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="产品编码" prop="productCode">
                <el-input v-model="queryParams.productCode" placeholder="请输入产品编码" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="险种编码" prop="insuranceCode">
                <el-input v-model="queryParams.insuranceCode" placeholder="请输入险种编码" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="险种编码名称" prop="insuranceCodeName">
                <el-input v-model="queryParams.insuranceCodeName" placeholder="请输入险种编码名称" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="险种名称" prop="insuranceName">
                <el-input v-model="queryParams.insuranceName" placeholder="请输入险种名称" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="用户PIN" prop="userPin">
                <el-input v-model="queryParams.userPin" placeholder="请输入用户PIN" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="店铺ID" prop="shopId">
                <el-input v-model="queryParams.shopId" placeholder="请输入店铺ID" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="店铺名称" prop="shopName">
                <el-input v-model="queryParams.shopName" placeholder="请输入店铺名称" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="商品编码" prop="commodityCode">
                <el-input v-model="queryParams.commodityCode" placeholder="请输入商品编码" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="商品名称" prop="commodityName">
                <el-input v-model="queryParams.commodityName" placeholder="请输入商品名称" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="主商品品牌" prop="brand">
                <el-input v-model="queryParams.brand" placeholder="请输入主商品品牌" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="主商品型号" prop="model">
                <el-input v-model="queryParams.model" placeholder="请输入主商品型号" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="收货省ID" prop="receiveProvinceId">
                <el-input v-model="queryParams.receiveProvinceId" placeholder="请输入收货省ID" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="主商品订单号" prop="mainOrderId">
                <el-input v-model="queryParams.mainOrderId" placeholder="请输入主商品订单号" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="商家ID" prop="merchantId">
                <el-input v-model="queryParams.merchantId" placeholder="请输入商家ID" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="一级类目ID" prop="firstCategoryId">
                <el-input v-model="queryParams.firstCategoryId" placeholder="请输入一级类目ID" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="二级类目ID" prop="secondCategoryId">
                <el-input v-model="queryParams.secondCategoryId" placeholder="请输入二级类目ID" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="主商品三级类目" prop="thirdCategoryName">
                <el-input v-model="queryParams.thirdCategoryName" placeholder="请输入主商品三级类目" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="是否实收" prop="isReceived">
                <el-input v-model="queryParams.isReceived" placeholder="请输入是否实收" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="是否共保" prop="isCoInsurance">
                <el-input v-model="queryParams.isCoInsurance" placeholder="请输入是否共保" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="业务来源" prop="businessSource">
                <el-input v-model="queryParams.businessSource" placeholder="请输入业务来源" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <!-- <el-form-item label="应收保费(保费实收)" prop="premiumReceivable">
                <el-input v-model="queryParams.premiumReceivable" placeholder="请输入应收保费(保费实收)" clearable @keyup.enter="handleQuery" />
              </el-form-item> -->
              <!-- <el-form-item label="保额" prop="insuredAmount">
                <el-input v-model="queryParams.insuredAmount" placeholder="请输入保额" clearable @keyup.enter="handleQuery" />
              </el-form-item> -->
              <!-- <el-form-item label="保障期间值" prop="coveragePeriod">
                <el-input v-model="queryParams.coveragePeriod" placeholder="请输入保障期间值" clearable @keyup.enter="handleQuery" />
              </el-form-item> -->
              <!-- <el-form-item label="标的物数量" prop="subjectQuantity">
                <el-input v-model="queryParams.subjectQuantity" placeholder="请输入标的物数量" clearable @keyup.enter="handleQuery" />
              </el-form-item> -->
              <!-- <el-form-item label="主商品京东价" prop="mainCommodityPrice">
                <el-input v-model="queryParams.mainCommodityPrice" placeholder="请输入主商品京东价" clearable @keyup.enter="handleQuery" />
              </el-form-item> -->
              <!-- <el-form-item label="标的物类目ID" prop="subjectCategoryId">
                <el-input v-model="queryParams.subjectCategoryId" placeholder="请输入标的物类目ID" clearable @keyup.enter="handleQuery" />
              </el-form-item> -->
              <!-- <el-form-item label="佣金率" prop="commissionRate">
                <el-input v-model="queryParams.commissionRate" placeholder="请输入佣金率" clearable @keyup.enter="handleQuery" />
              </el-form-item> -->
            </div>
            <div style="float: right">
              <el-form-item>
                <el-button type="success" icon="ArrowDown" @click="expandQuery">{{ isexpand ? '收起' : '展开' }}</el-button>
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
              </el-form-item>
            </div>
          </el-form>
        </el-card>
      </div>
    </transition>

    <el-card shadow="never">
      <template #header>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-upload
              v-model:file-list="fileList"
              class="upload-demo"
              action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
              multiple
              :on-preview="handlePreview"
              :on-remove="handleRemove"
              :before-remove="beforeRemove"
              :limit="1"
              :on-exceed="handleExceed"
            >
              <el-button type="primary" plain icon="Upload" v-hasPermi="['system:main:add']">承保单导入</el-button>
              <!-- <template #tip>
                <div class="el-upload__tip">jpg/png files with a size less than 500KB.</div>
              </template> -->
            </el-upload>
            <!-- <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['sz:policy:add']">新增</el-button> -->
          </el-col>
          <el-col :span="1.5">
            <el-upload
              v-model:file-list="fileList"
              class="upload-demo"
              action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
              multiple
              :on-preview="handlePreview"
              :on-remove="handleRemove"
              :before-remove="beforeRemove"
              :limit="1"
              :on-exceed="handleExceed"
            >
              <el-button type="success" plain icon="Upload" v-hasPermi="['system:main:add']">保单号导入</el-button>
              <!-- <template #tip>
                <div class="el-upload__tip">jpg/png files with a size less than 500KB.</div>
              </template> -->
            </el-upload>
            <!-- <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['sz:policy:edit']">修改</el-button> -->
          </el-col>
          <el-col :span="1.5">
            <el-upload
              v-model:file-list="fileList"
              class="upload-demo"
              action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
              multiple
              :on-preview="handlePreview"
              :on-remove="handleRemove"
              :before-remove="beforeRemove"
              :limit="1"
              :on-exceed="handleExceed"
            >
              <el-button type="danger" plain icon="Upload" v-hasPermi="['system:main:add']">实收导入</el-button>
              <!-- <template #tip>
                <div class="el-upload__tip">jpg/png files with a size less than 500KB.</div>
              </template> -->
            </el-upload>
            <!-- <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['sz:policy:remove']"
              >删除</el-button
            > -->
          </el-col>
          <el-col :span="1.5">
            <el-upload
              v-model:file-list="fileList"
              class="upload-demo"
              action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
              multiple
              :on-preview="handlePreview"
              :on-remove="handleRemove"
              :before-remove="beforeRemove"
              :limit="1"
              :on-exceed="handleExceed"
            >
              <el-button type="warning" plain icon="Upload" v-hasPermi="['system:main:add']">共保导入</el-button>
              <!-- <template #tip>
                <div class="el-upload__tip">jpg/png files with a size less than 500KB.</div>
              </template> -->
            </el-upload>
          </el-col>
          <el-col :span="1.5">
            <el-button type="info" plain icon="Download" @click="handleExport" v-hasPermi="['sz:policy:export']">导出</el-button>
          </el-col>
          <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
      </template>

      <el-table v-loading="loading" border :data="policyList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="自增主键" align="center" prop="id" v-if="true" />
        <el-table-column label="保单号" align="center" prop="policyId" />
        <el-table-column label="投保单号" align="center" prop="applicationId" />
        <el-table-column label="保单生效时间" align="center" prop="effectiveTime" />
        <el-table-column label="保单终止时间" align="center" prop="expireTime" />
        <el-table-column label="产品编码" align="center" prop="productCode" />
        <el-table-column label="险种编码" align="center" prop="insuranceCode" />
        <el-table-column label="险种编码名称" align="center" prop="insuranceCodeName" />
        <el-table-column label="险种名称" align="center" prop="insuranceName" />
        <el-table-column label="用户PIN" align="center" prop="userPin" />
        <el-table-column label="店铺ID" align="center" prop="shopId" />
        <el-table-column label="店铺名称" align="center" prop="shopName" />
        <el-table-column label="商品编码" align="center" prop="commodityCode" />
        <el-table-column label="商品名称" align="center" prop="commodityName" />
        <el-table-column label="主商品品牌" align="center" prop="brand" />
        <el-table-column label="主商品型号" align="center" prop="model" />
        <el-table-column label="收货省ID" align="center" prop="receiveProvinceId" />
        <el-table-column label="主商品订单号" align="center" prop="mainOrderId" />
        <el-table-column label="商家ID" align="center" prop="merchantId" />
        <el-table-column label="一级类目ID" align="center" prop="firstCategoryId" />
        <el-table-column label="二级类目ID" align="center" prop="secondCategoryId" />
        <el-table-column label="主商品三级类目" align="center" prop="thirdCategoryName" />
        <el-table-column label="保单状态" align="center" prop="policyStatus" />
        <el-table-column label="是否实收" align="center" prop="isReceived" />
        <el-table-column label="是否共保" align="center" prop="isCoInsurance" />
        <el-table-column label="业务来源" align="center" prop="businessSource" />
        <el-table-column label="保单创建日期" align="center" prop="createDate" v-if="true" />
        <el-table-column label="应收保费(保费实收)" align="center" prop="premiumReceivable" />
        <el-table-column label="保额" align="center" prop="insuredAmount" />
        <el-table-column label="保障期间值" align="center" prop="coveragePeriod" />
        <el-table-column label="标的物数量" align="center" prop="subjectQuantity" />
        <el-table-column label="主商品京东价" align="center" prop="mainCommodityPrice" />
        <el-table-column label="标的物类目ID" align="center" prop="subjectCategoryId" />
        <el-table-column label="佣金率" align="center" prop="commissionRate" />
        <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-tooltip content="修改" placement="top">
              <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['sz:policy:edit']"></el-button>
            </el-tooltip>
            <el-tooltip content="删除" placement="top">
              <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['sz:policy:remove']"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
    </el-card>
    <!-- 添加或修改承保单主对话框 :rules="rules"-->
    <el-dialog :title="dialog.title" v-model="dialog.visible" width="90%" append-to-body>
      <el-form ref="policyFormRef" :model="form" label-width="145" :inline="true" class="demo-form-inline">
        <el-card>
          <el-form-item label="保单号" prop="policyId">
            <el-input v-model="form.policyId" placeholder="请输入保单号" />
          </el-form-item>
          <el-form-item label="投保单号" prop="applicationId">
            <el-input v-model="form.applicationId" placeholder="请输入投保单号" />
          </el-form-item>
          <el-form-item label="投保状态" prop="applicationId">
            <el-input v-model="form.isReceived" placeholder="请输入投保状态" />
          </el-form-item>
          <el-form-item label="保单生效时间" prop="effectiveTime">
            <el-input v-model="form.effectiveTime" placeholder="请输入保单生效时间" />
          </el-form-item>
          <el-form-item label="保单终止时间" prop="expireTime">
            <el-input v-model="form.expireTime" placeholder="请输入保单终止时间" />
          </el-form-item>
          <el-form-item label="用户PIN" prop="userPin">
            <el-input v-model="form.userPin" placeholder="请输入用户PIN" />
          </el-form-item>
        </el-card>
        <el-card>
          <el-form-item label="产品编码" prop="productCode">
            <el-input v-model="form.productCode" placeholder="请输入产品编码" />
          </el-form-item>
          <el-form-item label="险种编码" prop="insuranceCode">
            <el-input v-model="form.insuranceCode" placeholder="请输入险种编码" />
          </el-form-item>
          <el-form-item label="险种编码名称" prop="insuranceCodeName">
            <el-input v-model="form.insuranceCodeName" placeholder="请输入险种编码名称" />
          </el-form-item>
          <el-form-item label="险种名称" prop="insuranceName">
            <el-input v-model="form.insuranceName" placeholder="请输入险种名称" />
          </el-form-item>
          <el-form-item label="保额" prop="insuredAmount">
            <el-input v-model="form.insuredAmount" placeholder="请输入保额" />
          </el-form-item>
          <el-form-item label="应收保费(保费实收)" prop="premiumReceivable">
            <el-input v-model="form.premiumReceivable" placeholder="请输入应收保费(保费实收)" />
          </el-form-item>
          <el-form-item label="保障期间值" prop="coveragePeriod">
            <el-input v-model="form.coveragePeriod" placeholder="请输入保障期间值" />
          </el-form-item>
        </el-card>
        <el-card>
          <el-form-item label="店铺ID" prop="shopId">
            <el-input v-model="form.shopId" placeholder="请输入店铺ID" />
          </el-form-item>
          <el-form-item label="店铺名称" prop="shopName">
            <el-input v-model="form.shopName" placeholder="请输入店铺名称" />
          </el-form-item>
          <el-form-item label="商家ID" prop="merchantId">
            <el-input v-model="form.merchantId" placeholder="请输入商家ID" />
          </el-form-item>
          <el-form-item label="佣金率" prop="commissionRate">
            <el-input v-model="form.commissionRate" placeholder="请输入佣金率" />
          </el-form-item>
          <el-form-item label="业务来源" prop="businessSource">
            <el-input v-model="form.businessSource" placeholder="请输入业务来源" />
          </el-form-item>
        </el-card>
        <el-card>
          <el-form-item label="商品编码" prop="commodityCode">
            <el-input v-model="form.commodityCode" placeholder="请输入商品编码" />
          </el-form-item>
          <el-form-item label="商品名称" prop="commodityName">
            <el-input v-model="form.commodityName" placeholder="请输入商品名称" />
          </el-form-item>
          <el-form-item label="主商品订单号" prop="mainOrderId">
            <el-input v-model="form.mainOrderId" placeholder="请输入主商品订单号" />
          </el-form-item>
          <el-form-item label="主商品品牌" prop="brand">
            <el-input v-model="form.brand" placeholder="请输入主商品品牌" />
          </el-form-item>
          <el-form-item label="主商品型号" prop="model">
            <el-input v-model="form.model" placeholder="请输入主商品型号" />
          </el-form-item>
          <el-form-item label="主商品京东价" prop="mainCommodityPrice">
            <el-input v-model="form.mainCommodityPrice" placeholder="请输入主商品京东价" />
          </el-form-item>
          <el-form-item label="一级类目ID" prop="firstCategoryId">
            <el-input v-model="form.firstCategoryId" placeholder="请输入一级类目ID" />
          </el-form-item>
          <el-form-item label="二级类目ID" prop="secondCategoryId">
            <el-input v-model="form.secondCategoryId" placeholder="请输入二级类目ID" />
          </el-form-item>
          <el-form-item label="主商品三级类目" prop="thirdCategoryName">
            <el-input v-model="form.thirdCategoryName" placeholder="请输入主商品三级类目" />
          </el-form-item>
          <el-form-item label="标的物类目ID" prop="subjectCategoryId">
            <el-input v-model="form.subjectCategoryId" placeholder="请输入标的物类目ID" />
          </el-form-item>
          <el-form-item label="标的物数量" prop="subjectQuantity">
            <el-input v-model="form.subjectQuantity" placeholder="请输入标的物数量" />
          </el-form-item>
          <el-form-item label="收货省ID" prop="receiveProvinceId">
            <el-input v-model="form.receiveProvinceId" placeholder="请输入收货省ID" />
          </el-form-item>
        </el-card>
        <el-card>
          <el-form-item label="是否实收" prop="isReceived">
            <el-input v-model="form.isReceived" placeholder="请输入是否实收" />
          </el-form-item>
          <el-form-item label="是否共保" prop="isCoInsurance">
            <el-input v-model="form.isCoInsurance" placeholder="请输入是否共保" />
          </el-form-item>
        </el-card>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <!-- <el-button :loading="buttonLoading" type="primary" @click="submitForm">确定</el-button> -->
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Policy" lang="ts">
import { listPolicy, getPolicy, delPolicy, addPolicy, updatePolicy } from '@/api/system/policy';
import { PolicyVO, PolicyQuery, PolicyForm } from '@/api/system/policy/types';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;

const policyList = ref<PolicyVO[]>([]);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);

const queryFormRef = ref<ElFormInstance>();
const policyFormRef = ref<ElFormInstance>();

const dialog = reactive<DialogOption>({
  visible: false,
  title: ''
});

const isexpand = ref(false);

const initFormData: PolicyForm = {
  id: undefined,
  policyId: undefined,
  applicationId: undefined,
  effectiveTime: undefined,
  expireTime: undefined,
  productCode: undefined,
  insuranceCode: undefined,
  insuranceCodeName: undefined,
  insuranceName: undefined,
  userPin: undefined,
  shopId: undefined,
  shopName: undefined,
  commodityCode: undefined,
  commodityName: undefined,
  brand: undefined,
  model: undefined,
  receiveProvinceId: undefined,
  mainOrderId: undefined,
  merchantId: undefined,
  firstCategoryId: undefined,
  secondCategoryId: undefined,
  thirdCategoryName: undefined,
  policyStatus: undefined,
  isReceived: undefined,
  isCoInsurance: undefined,
  businessSource: undefined,
  createDate: undefined,
  premiumReceivable: undefined,
  insuredAmount: undefined,
  coveragePeriod: undefined,
  subjectQuantity: undefined,
  mainCommodityPrice: undefined,
  subjectCategoryId: undefined,
  commissionRate: undefined
};
const data = reactive<PageData<PolicyForm, PolicyQuery>>({
  form: { ...initFormData },
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    policyId: undefined,
    applicationId: undefined,
    effectiveTime: undefined,
    expireTime: undefined,
    productCode: undefined,
    insuranceCode: undefined,
    insuranceCodeName: undefined,
    insuranceName: undefined,
    userPin: undefined,
    shopId: undefined,
    shopName: undefined,
    commodityCode: undefined,
    commodityName: undefined,
    brand: undefined,
    model: undefined,
    receiveProvinceId: undefined,
    mainOrderId: undefined,
    merchantId: undefined,
    firstCategoryId: undefined,
    secondCategoryId: undefined,
    thirdCategoryName: undefined,
    policyStatus: undefined,
    isReceived: undefined,
    isCoInsurance: undefined,
    businessSource: undefined,
    premiumReceivable: undefined,
    insuredAmount: undefined,
    coveragePeriod: undefined,
    subjectQuantity: undefined,
    mainCommodityPrice: undefined,
    subjectCategoryId: undefined,
    commissionRate: undefined,
    params: {}
  },
  rules: {
    id: [{ required: true, message: '自增主键不能为空', trigger: 'blur' }],
    policyId: [{ required: true, message: '保单号不能为空', trigger: 'blur' }],
    applicationId: [{ required: true, message: '投保单号不能为空', trigger: 'blur' }],
    effectiveTime: [{ required: true, message: '保单生效时间不能为空', trigger: 'blur' }],
    expireTime: [{ required: true, message: '保单终止时间不能为空', trigger: 'blur' }],
    productCode: [{ required: true, message: '产品编码不能为空', trigger: 'blur' }],
    insuranceCode: [{ required: true, message: '险种编码不能为空', trigger: 'blur' }],
    insuranceCodeName: [{ required: true, message: '险种编码名称不能为空', trigger: 'blur' }],
    insuranceName: [{ required: true, message: '险种名称不能为空', trigger: 'blur' }],
    userPin: [{ required: true, message: '用户PIN不能为空', trigger: 'blur' }],
    shopId: [{ required: true, message: '店铺ID不能为空', trigger: 'blur' }],
    shopName: [{ required: true, message: '店铺名称不能为空', trigger: 'blur' }],
    commodityCode: [{ required: true, message: '商品编码不能为空', trigger: 'blur' }],
    commodityName: [{ required: true, message: '商品名称不能为空', trigger: 'blur' }],
    brand: [{ required: true, message: '主商品品牌不能为空', trigger: 'blur' }],
    model: [{ required: true, message: '主商品型号不能为空', trigger: 'blur' }],
    receiveProvinceId: [{ required: true, message: '收货省ID不能为空', trigger: 'blur' }],
    mainOrderId: [{ required: true, message: '主商品订单号不能为空', trigger: 'blur' }],
    merchantId: [{ required: true, message: '商家ID不能为空', trigger: 'blur' }],
    firstCategoryId: [{ required: true, message: '一级类目ID不能为空', trigger: 'blur' }],
    secondCategoryId: [{ required: true, message: '二级类目ID不能为空', trigger: 'blur' }],
    thirdCategoryName: [{ required: true, message: '主商品三级类目不能为空', trigger: 'blur' }],
    policyStatus: [{ required: true, message: '保单状态不能为空', trigger: 'change' }],
    isReceived: [{ required: true, message: '是否实收不能为空', trigger: 'blur' }],
    isCoInsurance: [{ required: true, message: '是否共保不能为空', trigger: 'blur' }],
    businessSource: [{ required: true, message: '业务来源不能为空', trigger: 'blur' }],
    createDate: [{ required: true, message: '保单创建日期不能为空', trigger: 'blur' }]
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询承保单主列表 */
const getList = async () => {
  loading.value = true;
  const res = await listPolicy(queryParams.value);
  policyList.value = res.rows;
  total.value = res.total;
  loading.value = false;
};

/** 取消按钮 */
const cancel = () => {
  reset();
  dialog.visible = false;
};

/** 表单重置 */
const reset = () => {
  form.value = { ...initFormData };
  policyFormRef.value?.resetFields();
};

/** 展开更多按钮操作 */
const expandQuery = () => {
  isexpand.value = !isexpand.value;
};

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  handleQuery();
};

/** 多选框选中数据 */
const handleSelectionChange = (selection: PolicyVO[]) => {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
};

/** 新增按钮操作 */
const handleAdd = () => {
  reset();
  dialog.visible = true;
  dialog.title = '承保单';
};

/** 修改按钮操作 */
const handleUpdate = async (row?: PolicyVO) => {
  reset();
  const _id = row?.id || ids.value[0];
  const res = await getPolicy(_id);
  Object.assign(form.value, res.data);
  dialog.visible = true;
  dialog.title = '修改承保单主';
};

/** 提交按钮 */
const submitForm = () => {
  policyFormRef.value?.validate(async (valid: boolean) => {
    if (valid) {
      buttonLoading.value = true;
      if (form.value.id) {
        await updatePolicy(form.value).finally(() => (buttonLoading.value = false));
      } else {
        await addPolicy(form.value).finally(() => (buttonLoading.value = false));
      }
      proxy?.$modal.msgSuccess('操作成功');
      dialog.visible = false;
      await getList();
    }
  });
};

/** 删除按钮操作 */
const handleDelete = async (row?: PolicyVO) => {
  const _ids = row?.id || ids.value;
  await proxy?.$modal.confirm('是否确认删除承保单主编号为"' + _ids + '"的数据项？').finally(() => (loading.value = false));
  await delPolicy(_ids);
  proxy?.$modal.msgSuccess('删除成功');
  await getList();
};

/** 导出按钮操作 */
const handleExport = () => {
  proxy?.download(
    'sz/policy/export',
    {
      ...queryParams.value
    },
    `policy_${new Date().getTime()}.xlsx`
  );
};

onMounted(() => {
  getList();
});
</script>
<style scoped lang="scss">
:deep(.el-form--inline .el-form-item) {
  margin-right: 25px !important;
}
.demo-form-inline {
  :deep(.el-form-item) {
    vertical-align: baseline !important;
  }
  :deep(.el-input) {
    width: 360px !important;
  }
  :deep(.el-textarea) {
    width: 360px !important;
  }
  :deep(.el-textarea__inner) {
    min-height: 100px !important;
  }
}
:deep(.el-card) {
  margin-bottom: 20px;
}
:deep(.el-card__body) {
  padding: 20px 0 0 0 !important;
}
</style>
